﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;

namespace LightWeb.Blog.Common
{
    public class Utility
    {
        public static string GetJSONFromObject(object Source)              //將物件轉為JSON
        {
            JavaScriptSerializer JSONSerializer = new JavaScriptSerializer();
            return JSONSerializer.Serialize(Source);
        }
        public static object GetObjectFromJSON(string JSON, Type ObjectType)//將JSON轉為物件
        {
            JavaScriptSerializer JSONSerializer = new JavaScriptSerializer();
            return JSONSerializer.Deserialize(JSON, ObjectType);
        }
        public static T GetTypetFromJSON<T>(string JSON)//將JSON轉為物件
            where T : class
        {
            JavaScriptSerializer JSONSerializer = new JavaScriptSerializer();
            return JSONSerializer.Deserialize(JSON, typeof(T)) as T;
        }
    }
}